package postprocessortest;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

/**
 * @author: mornd
 * @dateTime: 2023/5/14 - 15:57
 */
@ComponentScan
public class Demo {
    public static void main(String[] args) {
        ConfigurableApplicationContext run = new AnnotationConfigApplicationContext(Demo.class);
        A bean = run.getBean(A.class);
        System.out.println(bean);
    }

    @Component
    static class A {
    }

    @Component
    static class B {
    }

    @Component
    static class C {
    }

    @Component
    static class MyPostProcessor implements BeanPostProcessor {
        @Override
        public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
            System.out.println("before:" + beanName);
            return bean;
        }

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            System.out.println("after:" + beanName);
            return bean;
        }
    }
}
